@insta-dev01/insta-plugin-openclaw 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +23 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/channel/346/265/201/347/250/213/345/233/276.md +477 -0
- package/index.ts +198 -0
- package/openclaw.plugin.json +11 -0
- package/package.json +55 -0
- package/src/channel/config.ts +27 -0
- package/src/channel/connection.ts +341 -0
- package/src/channel/dispatcher.ts +374 -0
- package/src/channel/index.ts +173 -0
- package/src/channel/logger.ts +36 -0
- package/src/channel/protocol.ts +265 -0
- package/src/channel/registrar.ts +172 -0
- package/src/channel/registration-store.ts +77 -0
- package/src/channel/types.ts +102 -0
- package/src/core/index.ts +13 -0
- package/src/core/register-identity.ts +326 -0
- package/src/core/task-api.ts +168 -0
- package/src/core/urls.ts +52 -0
- package/src/prompt/job.md +21 -0
- package/src/tools/get-plugin-profile.ts +152 -0
- package/src/tools/grab-task.ts +133 -0
- package/src/tools/list-tasks.ts +135 -0
- package/src/tools/propose-registration.ts +116 -0
- package/src/tools/register-identity.ts +121 -0
- package/src/tools/submit-deliverable.ts +268 -0
- package/src/tools/upload-artifact.ts +222 -0
- package/src/utils/file-lock.ts +43 -0
- package/src/utils/profile.ts +45 -0
- package/src/utils/session.ts +30 -0
- package/tests/profile.test.ts +70 -0
- package/tests/session.test.ts +53 -0
- package/tsconfig.json +49 -0
- package/vitest.config.ts +26 -0
package/.env.example
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# WebSocket server URL
|
|
2
|
+
INSTACLAW_WS_URL=wss://claw.int-os.com/ws/chat
|
|
3
|
+
|
|
4
|
+
# Heartbeat interval (ms)
|
|
5
|
+
INSTACLAW_HEARTBEAT_INTERVAL=30000
|
|
6
|
+
|
|
7
|
+
# Timeout threshold (ms)
|
|
8
|
+
INSTACLAW_TIMEOUT_THRESHOLD=60000
|
|
9
|
+
|
|
10
|
+
# SDK request timeout (ms)
|
|
11
|
+
SDK_REQUEST_TIMEOUT=43200000
|
|
12
|
+
|
|
13
|
+
# Max concurrent SDK requests
|
|
14
|
+
MAX_CONCURRENT_REQUESTS=10
|
|
15
|
+
|
|
16
|
+
# Artifact upload endpoint
|
|
17
|
+
INSTACLAW_ARTIFACT_UPLOAD_AND_BIND_URL=http://claw.int-os.com/artifact/upload-and-bind
|
|
18
|
+
|
|
19
|
+
# Base URL for InstaClaw API (optional, defaults to https://claw.int-os.com)
|
|
20
|
+
INSTACLAW_PROFILE_CREATE_URL=https://claw.int-os.com/profiles/create
|
|
21
|
+
|
|
22
|
+
# Task pool Bot API base URL (used by list-tasks / grab-task / submit-deliverable tools)
|
|
23
|
+
INSTACLAW_TASK_API_BASE_URL=https://claw.int-os.com
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 引态科技
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
# Channel 流程图
|
|
2
|
+
|
|
3
|
+
## 1. 整体架构
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
7
|
+
│ InstaClaw 平台 │
|
|
8
|
+
│ ┌──────────┐ ┌──────────────┐ ┌─────────────────────┐ │
|
|
9
|
+
│ │ Control │ │ Message │ │ Registration │ │
|
|
10
|
+
│ │ UI │ │ Broker │ │ API │ │
|
|
11
|
+
│ └────┬─────┘ └──────┬───────┘ └──────────┬──────────┘ │
|
|
12
|
+
└───────┼─────────────────┼───────────────────────┼──────────────────┘
|
|
13
|
+
│ WebSocket │ WebSocket │ HTTPS
|
|
14
|
+
│ (控制指令) │ (用户消息) │ (注册)
|
|
15
|
+
▼ ▼ ▼
|
|
16
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
17
|
+
│ ChannelPlugin │
|
|
18
|
+
│ │
|
|
19
|
+
│ ┌────────────────┐ ┌─────────────────┐ ┌───────────────────┐ │
|
|
20
|
+
│ │ Connection │ │ Dispatcher │ │ Registrar │ │
|
|
21
|
+
│ │ Manager │ │ (请求分发) │ │ (自动注册) │ │
|
|
22
|
+
│ │ │ │ │ │ │ │
|
|
23
|
+
│ │ • 心跳保活 │ │ • 解析请求 │ │ • 轮询凭证 │ │
|
|
24
|
+
│ │ • 断线重连 │ │ • 调用 AI │ │ • AI 注册代理 │ │
|
|
25
|
+
│ │ • 状态机管理 │ │ • 流式响应 │ │ • 用户确认 │ │
|
|
26
|
+
│ └───────┬────────┘ └───────┬─────────┘ └───────┬───────────┘ │
|
|
27
|
+
│ │ │ │ │
|
|
28
|
+
│ ┌───────┴───────────────────┴─────────────────────┴───────────┐ │
|
|
29
|
+
│ │ Protocol (协议层) │ │
|
|
30
|
+
│ │ 请求解析 ←→ 事件生成 ←→ Open Responses 协议 │ │
|
|
31
|
+
│ └─────────────────────────────────────────────────────────────┘ │
|
|
32
|
+
│ │ │
|
|
33
|
+
│ ┌───────────────────────────┴──────────────────────────────────┐ │
|
|
34
|
+
│ │ Store (状态管理) │ │
|
|
35
|
+
│ │ • activeConnections: Map<accountId, WebSocket> │ │
|
|
36
|
+
│ │ • pendingRegistration: Proposal | null │ │
|
|
37
|
+
│ │ • agentRunning: boolean │ │
|
|
38
|
+
│ └──────────────────────────────────────────────────────────────┘ │
|
|
39
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 2. 自动注册流程
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
┌──────────┐
|
|
48
|
+
│ 启动插件 │
|
|
49
|
+
│startAccount│
|
|
50
|
+
└────┬─────┘
|
|
51
|
+
│
|
|
52
|
+
▼
|
|
53
|
+
┌──────────────┐ 每10秒轮询
|
|
54
|
+
│ 轮询凭证文件 │◄──────────────┐
|
|
55
|
+
│ profile.json │ │
|
|
56
|
+
└────┬─────────┘ │
|
|
57
|
+
│ │
|
|
58
|
+
▼ │
|
|
59
|
+
┌──────────┐ │
|
|
60
|
+
│ 凭证存在? │──── 否 ───────────┤
|
|
61
|
+
└────┬─────┘ │
|
|
62
|
+
│ 是 │
|
|
63
|
+
▼ │
|
|
64
|
+
┌──────────────┐ ┌──────────────────────┐
|
|
65
|
+
│ 建立 WebSocket│ │ triggerRegistration │
|
|
66
|
+
│ 连接平台 │ │ Agent() │
|
|
67
|
+
└──────────────┘ └──────────┬───────────┘
|
|
68
|
+
│
|
|
69
|
+
▼
|
|
70
|
+
┌─────────────────────┐
|
|
71
|
+
│ AI 注册代理运行 │
|
|
72
|
+
│ 分析项目信息 │
|
|
73
|
+
└──────────┬──────────┘
|
|
74
|
+
│
|
|
75
|
+
▼
|
|
76
|
+
┌──────────────────────┐
|
|
77
|
+
│ 调用工具 │
|
|
78
|
+
│ insta_propose_ │
|
|
79
|
+
│ registration │
|
|
80
|
+
│ (建议注册参数) │
|
|
81
|
+
└──────────┬───────────┘
|
|
82
|
+
│
|
|
83
|
+
▼
|
|
84
|
+
┌─────────────────────┐
|
|
85
|
+
│ 存储到 registration │
|
|
86
|
+
│ Store (内存) │
|
|
87
|
+
│ status: pending │
|
|
88
|
+
└──────────┬──────────┘
|
|
89
|
+
│
|
|
90
|
+
▼
|
|
91
|
+
┌───────────────────────────────┐
|
|
92
|
+
│ Control UI 展示 │
|
|
93
|
+
│ ┌──────────────────────────┐ │
|
|
94
|
+
│ │ 注册确认表单 │ │
|
|
95
|
+
│ │ │ │
|
|
96
|
+
│ │ 名称: [________] │ │
|
|
97
|
+
│ │ 描述: [________] │ │
|
|
98
|
+
│ │ 头像: [________] │ │
|
|
99
|
+
│ │ 标签: [________] │ │
|
|
100
|
+
│ │ 类型: [________] │ │
|
|
101
|
+
│ │ │ │
|
|
102
|
+
│ │ [ 确认 ] [ 取消 ] │ │
|
|
103
|
+
│ └──────────────────────────┘ │
|
|
104
|
+
└───────────────┬───────────────┘
|
|
105
|
+
│ 用户确认
|
|
106
|
+
▼
|
|
107
|
+
┌──────────────────────┐
|
|
108
|
+
│ 提交注册 │
|
|
109
|
+
│ instaclaw.registration│
|
|
110
|
+
│ .submit │
|
|
111
|
+
└──────────┬───────────┘
|
|
112
|
+
│
|
|
113
|
+
▼
|
|
114
|
+
┌──────────────────────┐
|
|
115
|
+
│ 调用 registerIdentity │
|
|
116
|
+
│ API → 平台注册 │
|
|
117
|
+
└──────────┬───────────┘
|
|
118
|
+
│
|
|
119
|
+
▼
|
|
120
|
+
┌──────────────────────┐
|
|
121
|
+
│ 写入 profile.json │
|
|
122
|
+
│ 清除 pending 状态 │
|
|
123
|
+
└──────────┬───────────┘
|
|
124
|
+
│
|
|
125
|
+
▼
|
|
126
|
+
┌──────────────────────┐
|
|
127
|
+
│ 下一轮轮询发现凭证 │──────────┐
|
|
128
|
+
│ → 建立连接 │ │
|
|
129
|
+
└──────────────────────┘ │
|
|
130
|
+
│
|
|
131
|
+
┌──────────────────────┐ │
|
|
132
|
+
│ 若用户取消 │ │
|
|
133
|
+
│ → 等待后重新触发 │──────────┘
|
|
134
|
+
└──────────────────────┘
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## 3. AI 对话请求处理流程
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
InstaClaw 平台 ChannelPlugin
|
|
143
|
+
───────────────── ─────────────────
|
|
144
|
+
|
|
145
|
+
┌──────────┐
|
|
146
|
+
│ 用户发送 │
|
|
147
|
+
│ 消息 │
|
|
148
|
+
└────┬─────┘
|
|
149
|
+
│ WebSocket Message
|
|
150
|
+
│ Topic: /v1.0/im/user/messages
|
|
151
|
+
▼
|
|
152
|
+
┌──────────────────┐
|
|
153
|
+
│ Connection │
|
|
154
|
+
│ onMessage() │
|
|
155
|
+
└───────┬──────────┘
|
|
156
|
+
│
|
|
157
|
+
▼
|
|
158
|
+
┌──────────────────┐
|
|
159
|
+
│ parseRequest() │
|
|
160
|
+
│ 解析 JSON │
|
|
161
|
+
│ · content │
|
|
162
|
+
│ · messageId │
|
|
163
|
+
│ · sessionId │
|
|
164
|
+
└───────┬──────────┘
|
|
165
|
+
│
|
|
166
|
+
▼
|
|
167
|
+
┌──────────────────┐
|
|
168
|
+
│ SDKDispatcher │
|
|
169
|
+
│ dispatch() │
|
|
170
|
+
│ │
|
|
171
|
+
│ 创建 RequestContext│
|
|
172
|
+
│ · timeout 控制 │
|
|
173
|
+
│ · AbortController │
|
|
174
|
+
└───────┬──────────┘
|
|
175
|
+
│
|
|
176
|
+
▼
|
|
177
|
+
┌──────────────────────────────┐
|
|
178
|
+
│ dispatchReplyWithBuffered │
|
|
179
|
+
│ BlockDispatcher() │
|
|
180
|
+
│ │
|
|
181
|
+
│ 1. 构建 session key: │
|
|
182
|
+
│ "instaclaw:{accId}:{sessId}"│
|
|
183
|
+
│ │
|
|
184
|
+
│ 2. 注入系统提示 │
|
|
185
|
+
│ + session 上下文 │
|
|
186
|
+
│ │
|
|
187
|
+
│ 3. 设置流式回调 │
|
|
188
|
+
│ onPartialReply → 分块 │
|
|
189
|
+
│ deliver → 完成信号 │
|
|
190
|
+
└───────┬──────────────────────┘
|
|
191
|
+
│
|
|
192
|
+
┌──────────────┴──────────────┐
|
|
193
|
+
│ │
|
|
194
|
+
▼ │
|
|
195
|
+
┌──────────────┐ │
|
|
196
|
+
│ AI Runtime │ │
|
|
197
|
+
│ 处理 & 生成 │ │
|
|
198
|
+
└──────┬───────┘ │
|
|
199
|
+
│ │
|
|
200
|
+
▼ │
|
|
201
|
+
┌──────────────────────────────────────────────────┐ │
|
|
202
|
+
│ 流式事件序列 │ │
|
|
203
|
+
│ │ │
|
|
204
|
+
│ ① response.in_progress │ │
|
|
205
|
+
│ ┌────────────────────────────┐ │ │
|
|
206
|
+
│ │ 请求已开始处理 │ │ │
|
|
207
|
+
│ └────────────────────────────┘ │ │
|
|
208
|
+
│ │ │ │
|
|
209
|
+
│ ▼ │ │
|
|
210
|
+
│ ② response.output_item.added │ │
|
|
211
|
+
│ ┌────────────────────────────┐ │ │
|
|
212
|
+
│ │ 新消息条目已创建 │ │ │
|
|
213
|
+
│ └────────────────────────────┘ │ │
|
|
214
|
+
│ │ │ │
|
|
215
|
+
│ ▼ │
|
|
216
|
+
│ ③ response.output_text.delta (×N, 每50字符) │ │
|
|
217
|
+
│ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │
|
|
218
|
+
│ │ chunk│→│ chunk│→│ chunk│→│ chunk│ ... │ │
|
|
219
|
+
│ └──────┘ └──────┘ └──────┘ └──────┘ │ │
|
|
220
|
+
│ │ │ │
|
|
221
|
+
│ ▼ │ │
|
|
222
|
+
│ ④ response.content_part.done │ │
|
|
223
|
+
│ ┌────────────────────────────┐ │ │
|
|
224
|
+
│ │ 内容部分已完成 │ │ │
|
|
225
|
+
│ └────────────────────────────┘ │ │
|
|
226
|
+
│ │ │ │
|
|
227
|
+
│ ▼ │ │
|
|
228
|
+
│ ⑤ response.completed │ │
|
|
229
|
+
│ ┌────────────────────────────┐ │ │
|
|
230
|
+
│ │ 响应已完成 │ │ │
|
|
231
|
+
│ └────────────────────────────┘ │ │
|
|
232
|
+
└──────────────────────────────────────────────────┘ │
|
|
233
|
+
│ │
|
|
234
|
+
▼ │
|
|
235
|
+
┌──────────────┐ │
|
|
236
|
+
│ 发送至平台 │ │
|
|
237
|
+
│ WebSocket │ │
|
|
238
|
+
│ Topic: /v1.0/ │ │
|
|
239
|
+
│ im/bot/ │ │
|
|
240
|
+
│ messages │───────────────────────┘
|
|
241
|
+
└──────────────┘
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## 4. WebSocket 连接生命周期
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
┌──────────┐
|
|
250
|
+
│ 开始 │
|
|
251
|
+
└────┬─────┘
|
|
252
|
+
│
|
|
253
|
+
▼
|
|
254
|
+
┌─────────────┐
|
|
255
|
+
│ connecting │
|
|
256
|
+
│ 建立 WS 连接 │
|
|
257
|
+
└──────┬──────┘
|
|
258
|
+
│
|
|
259
|
+
┌──────────┴──────────┐
|
|
260
|
+
│ │
|
|
261
|
+
▼ ▼
|
|
262
|
+
┌─────────────┐ ┌───────────┐
|
|
263
|
+
│ connected │ │ 连接失败 │
|
|
264
|
+
│ 连接成功 │ └─────┬─────┘
|
|
265
|
+
└──────┬──────┘ │
|
|
266
|
+
│ │
|
|
267
|
+
▼ │
|
|
268
|
+
┌─────────────┐ │
|
|
269
|
+
│ 心跳保活 │ │
|
|
270
|
+
│ 每30s ping │ │
|
|
271
|
+
│ 3次超时断连 │ │
|
|
272
|
+
└──────┬──────┘ │
|
|
273
|
+
│ │
|
|
274
|
+
┌────────┴────────┐ │
|
|
275
|
+
│ │ │
|
|
276
|
+
▼ ▼ │
|
|
277
|
+
┌─────────┐ ┌───────────┐ │
|
|
278
|
+
│ 正常通信 │ │ 心跳超时 │ │
|
|
279
|
+
│ 收发消息 │ │ / 连接中断 │ │
|
|
280
|
+
└────┬────┘ └─────┬─────┘ │
|
|
281
|
+
│ │ │
|
|
282
|
+
│ ▼ │
|
|
283
|
+
│ ┌──────────────┐ │
|
|
284
|
+
│ │ disconnected │ │
|
|
285
|
+
│ └──────┬───────┘ │
|
|
286
|
+
│ │ │
|
|
287
|
+
│ ▼ │
|
|
288
|
+
│ ┌──────────────┐ │
|
|
289
|
+
│ │ reconnecting │ │
|
|
290
|
+
│ │ 指数退避+抖动 │◄────┘
|
|
291
|
+
│ │ 1s → 2s → 4s │
|
|
292
|
+
│ │ ... 最大 30s │
|
|
293
|
+
│ └──────┬───────┘
|
|
294
|
+
│ │
|
|
295
|
+
│ ┌──────┴──────┐
|
|
296
|
+
│ │ │
|
|
297
|
+
│ ▼ ▼
|
|
298
|
+
│ ┌──────────┐ ┌──────────┐
|
|
299
|
+
│ │ 重连成功 │ │ 重连失败 │
|
|
300
|
+
│ │ → connected│ │ → 继续退避 │──→ (回到 reconnecting)
|
|
301
|
+
│ └──────────┘ └──────────┘
|
|
302
|
+
│
|
|
303
|
+
▼
|
|
304
|
+
┌──────────┐
|
|
305
|
+
│ 插件卸载 │
|
|
306
|
+
│ 关闭连接 │
|
|
307
|
+
└──────────┘
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## 5. 消息协议格式
|
|
313
|
+
|
|
314
|
+
```
|
|
315
|
+
═══════════════════════════════════════════════════════
|
|
316
|
+
接收消息 (平台 → 插件)
|
|
317
|
+
═══════════════════════════════════════════════════════
|
|
318
|
+
|
|
319
|
+
Topic: /v1.0/im/user/messages
|
|
320
|
+
|
|
321
|
+
┌─────────────────────────────────────────┐
|
|
322
|
+
│ { │
|
|
323
|
+
│ "messageId": "msg_xxx", │
|
|
324
|
+
│ "sessionId": "sess_xxx", │
|
|
325
|
+
│ "input": [ │
|
|
326
|
+
│ { │
|
|
327
|
+
│ "type": "input_text", ────────── 文本消息
|
|
328
|
+
│ "text": "你好" │
|
|
329
|
+
│ }, │
|
|
330
|
+
│ { │
|
|
331
|
+
│ "type": "input_file", ────────── 文件附件
|
|
332
|
+
│ "file_id": "file_xxx" │
|
|
333
|
+
│ }, │
|
|
334
|
+
│ { │
|
|
335
|
+
│ "type": "input_image", ────────── 图片上传
|
|
336
|
+
│ "image_url": "https://..." │
|
|
337
|
+
│ } │
|
|
338
|
+
│ ] │
|
|
339
|
+
│ } │
|
|
340
|
+
└─────────────────────────────────────────┘
|
|
341
|
+
|
|
342
|
+
═══════════════════════════════════════════════════════
|
|
343
|
+
发送消息 (插件 → 平台)
|
|
344
|
+
═══════════════════════════════════════════════════════
|
|
345
|
+
|
|
346
|
+
Topic: /v1.0/im/bot/messages
|
|
347
|
+
|
|
348
|
+
┌─────────────────────────────────────────┐
|
|
349
|
+
│ { │
|
|
350
|
+
│ "type": "MESSAGE", │
|
|
351
|
+
│ "headers": { │
|
|
352
|
+
│ "message-id": "msg_xxx", │
|
|
353
|
+
│ "session-id": "sess_xxx" │
|
|
354
|
+
│ }, │
|
|
355
|
+
│ "data": "<event_json>" ───────────── Open Responses 事件 JSON
|
|
356
|
+
│ } │
|
|
357
|
+
└─────────────────────────────────────────┘
|
|
358
|
+
|
|
359
|
+
═══════════════════════════════════════════════════════
|
|
360
|
+
流式事件 (Open Responses 协议)
|
|
361
|
+
═══════════════════════════════════════════════════════
|
|
362
|
+
|
|
363
|
+
┌─ response.in_progress ─────────────────┐
|
|
364
|
+
│ { "type": "response.in_progress" } │
|
|
365
|
+
└────────────────────────────────────────┘
|
|
366
|
+
│
|
|
367
|
+
▼
|
|
368
|
+
┌─ response.output_item.added ───────────┐
|
|
369
|
+
│ { "type": "response.output_item.added"│
|
|
370
|
+
│ "item": { "type": "message", │
|
|
371
|
+
│ "role": "assistant" } } │
|
|
372
|
+
└────────────────────────────────────────┘
|
|
373
|
+
│
|
|
374
|
+
▼
|
|
375
|
+
┌─ response.output_text.delta ───────────┐
|
|
376
|
+
│ { "type": "response.output_text.delta"│
|
|
377
|
+
│ "delta": "每50字符为一个chunk" } │
|
|
378
|
+
│ × N 次 │
|
|
379
|
+
└────────────────────────────────────────┘
|
|
380
|
+
│
|
|
381
|
+
▼
|
|
382
|
+
┌─ response.content_part.done ───────────┐
|
|
383
|
+
│ { "type": "response.content_part.done"│
|
|
384
|
+
│ "part": { "text": "完整响应文本" } } │
|
|
385
|
+
└────────────────────────────────────────┘
|
|
386
|
+
│
|
|
387
|
+
▼
|
|
388
|
+
┌─ response.completed ───────────────────┐
|
|
389
|
+
│ { "type": "response.completed", │
|
|
390
|
+
│ "response": { "status": "completed"}│
|
|
391
|
+
└────────────────────────────────────────┘
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
## 6. 文件状态管理
|
|
397
|
+
|
|
398
|
+
```
|
|
399
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
400
|
+
│ 文件系统 │
|
|
401
|
+
│ │
|
|
402
|
+
│ .insta/ │
|
|
403
|
+
│ ├── config/ │
|
|
404
|
+
│ │ └── profile.json ─────────────────────────────────┐ │
|
|
405
|
+
│ │ { │ │
|
|
406
|
+
│ │ "app_key": "xxx", ← 平台凭证 │ │
|
|
407
|
+
│ │ "app_secret": "xxx", ← 平台凭证 │ │
|
|
408
|
+
│ │ "name": "AI助手", ← 显示名称 │ │
|
|
409
|
+
│ │ "description": "...", ← 插件描述 │ │
|
|
410
|
+
│ │ "avatar": "...", ← 头像 URL │ │
|
|
411
|
+
│ │ "claw_id": "...", ← 业务 ID │ │
|
|
412
|
+
│ │ "hourly_rate": 0, ← 计费费率 │ │
|
|
413
|
+
│ │ "scene_tags": [], ← 场景标签 │ │
|
|
414
|
+
│ │ "custom_tags": [], ← 自定义标签 │ │
|
|
415
|
+
│ │ "instance_type": "..." ← 部署模式 │ │
|
|
416
|
+
│ │ } │ │
|
|
417
|
+
│ │ │ │
|
|
418
|
+
│ └── .activate_session ──────────────────────────────────┤ │
|
|
419
|
+
│ { │ │
|
|
420
|
+
│ "session_token": "xxx" ← 激活会话令牌 │ │
|
|
421
|
+
│ } │ │
|
|
422
|
+
│ │ │
|
|
423
|
+
└──────────────────────────────────────────────────────────┘ │
|
|
424
|
+
│
|
|
425
|
+
┌──────────────────────────────────────────────────────────┐ │
|
|
426
|
+
│ 内存状态 (registration-store) │ │
|
|
427
|
+
│ │ │
|
|
428
|
+
│ _agentRunning: boolean ── AI 注册代理是否运行中 │ │
|
|
429
|
+
│ _pending: Proposal | null ── 待确认的注册提案 │ │
|
|
430
|
+
│ _baseDir: string | null ── 缓存的基础目录 │ │
|
|
431
|
+
│ │ │
|
|
432
|
+
│ activeConnections: ── 活跃 WebSocket 连接 │◄─┘
|
|
433
|
+
│ Map<accountId, WebSocket> │
|
|
434
|
+
│ │
|
|
435
|
+
└───────────────────────────────────────────────────────────┘
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## 7. 并发与错误处理
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
┌─────────────────────────────────────────────────────┐
|
|
444
|
+
│ 请求并发控制 │
|
|
445
|
+
│ │
|
|
446
|
+
│ 最大并发: 10 个请求 │
|
|
447
|
+
│ │
|
|
448
|
+
│ ┌─────┐ ┌─────┐ ┌─────┐ │
|
|
449
|
+
│ │ Req │ │ Req │ │ Req │ ... 最多 10 个 │
|
|
450
|
+
│ │ 1 │ │ 2 │ │ 3 │ │
|
|
451
|
+
│ └──┬──┘ └──┬──┘ └──┬──┘ │
|
|
452
|
+
│ │ │ │ │
|
|
453
|
+
│ ▼ ▼ ▼ │
|
|
454
|
+
│ 各自独立的 RequestContext │
|
|
455
|
+
│ 各自独立的 AbortController │
|
|
456
|
+
│ 各自独立的超时控制 │
|
|
457
|
+
└─────────────────────────────────────────────────────┘
|
|
458
|
+
|
|
459
|
+
┌─────────────────────────────────────────────────────┐
|
|
460
|
+
│ 错误处理策略 │
|
|
461
|
+
│ │
|
|
462
|
+
│ 请求失败 ────→ 生成 error 事件 ──→ 发送至平台 │
|
|
463
|
+
│ { │
|
|
464
|
+
│ "type": "response.failed", │
|
|
465
|
+
│ "error": { │
|
|
466
|
+
│ "code": "...", │
|
|
467
|
+
│ "message": "..." │
|
|
468
|
+
│ } │
|
|
469
|
+
│ } │
|
|
470
|
+
│ │
|
|
471
|
+
│ 连接中断 ────→ 触发重连 ──→ 指数退避重试 │
|
|
472
|
+
│ │
|
|
473
|
+
│ 注册失败 ────→ 清除状态 ──→ 下次轮询重新触发 │
|
|
474
|
+
│ │
|
|
475
|
+
│ AI 超时 ────→ AbortController ──→ 返回错误事件 │
|
|
476
|
+
└─────────────────────────────────────────────────────┘
|
|
477
|
+
```
|